package intjavatorpedo.client;

import intjavatorpedo.db.User;
import intjavatorpedo.ws.TorpedoInterface;

import java.util.List;

import javax.swing.AbstractListModel;

public class UserListModel extends AbstractListModel<String> {

	private TorpedoInterface torpedo;
	private List<User> users;
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public UserListModel(TorpedoInterface torpedo) {
		this.torpedo = torpedo;
	}
	
	public void refresh() {
		this.users = this.torpedo.getUsers();
		this.fireContentsChanged(this, 0, this.getSize() - 1);
	}
	
	@Override
	public String getElementAt(int index) {
		User user = this.users.get(index);
		return user.getName();
	}

	@Override
	public int getSize() {
		if (this.users == null)
			return 0;
		else
			return this.users.size();
	}

}
